<div>
	<!-- widget content -->
	<div class="widget-body">

		<form action="" method="post" id="checkout-form" class="smart-form">
			<header>
				<h2>
					业务子系统新增
					<button class="close" data-dismiss="modal">x</button>
				</h2>

			</header>
			<fieldset>
				<div id="dialog-alert"></div>
				<div class="row">
					<label class="label col col-3"><label style="color: red">*</label>业务系统</label>
					<section class="col col-8">
						<select id="businessSystem" name="businessSystem">
						</select>
					</section>
				</div>
				<div class="row">
					<label class="label col col-3"><label style="color: red">*</label>子系统名称</label>
					<section class="col col-8">
						<label class="input"> <input type="text" name="name"
							placeholder=" 输入子系统名称" class="required ">
						</label>
					</section>
				</div>
				<div class="row">
					<label class="label col col-3"><label style="color: red">*</label>备注</label>
					<section class="col col-8">
						<label class="textarea"> <textarea rows="3" name="description"
								class="custom-scroll required" placeholder=" 在此对此系统进行描述"></textarea>
						</label>
					</section>
				</div>
			</fieldset>
		</form>
	</div>
	<!-- end widget content -->

</div>
<div class="modal-footer">

	<button type="button" class="btn btn-default btn-sm"
		data-dismiss="modal">取消</button>
	<button type="submit" class="btn btn-primary btn-sm" id="submitbtn">
		保存</button>
</div>

<script>
	pageSetUp();
	var businessSystem, $businessSystem;
	var pagefunction = function() {
		sendGet("/upm_manager/v1.0/business_systems",
				fillSelect_businessSystem, DialogAlert, null);

		$businessSystem = $("#businessSystem").selectize({
			valueField : 'id',
			labelField : 'name',
			searchField : 'name',
			create : false,
			sortField : {
				field : 'name'
			},
			options : []
		});

		var errorClass = 'invalid';
		var errorElement = 'em';
		var option = {
			errorClass : errorClass,
			errorElement : errorElement,
			highlight : function(element) {
				$(element).parent().removeClass('state-success').addClass(
						"state-error");
				$(element).removeClass('valid');
			},
			unhighlight : function(element) {
				$(element).parent().removeClass("state-error").addClass(
						'state-success');
				$(element).addClass('valid');

			},
			// Rules for form validation
			// Messages for form validation
			messages : {
				name : {
					required : '请输入区域名称'
				},
				remark : {
					required : '请输入描述'
				}
			},
			errorPlacement : function(error, element) {
				if ($(element).next("div").hasClass("tooltip")) {
					$(element).attr("data-original-title", $(error).text())
							.tooltip("show");
				} else {
					$(element).attr("title", $(error).text()).tooltip("show");
				}
			},
			submitHandler : function(form) {
				//在这里生成需要提交的json数据
				var data = $('#checkout-form').serializeArray();
				var flg = true;
				if (data.businessSystem == "") {
					DialogAlert("请选择业务系统");
					flg = false;
				}
				var jsonData = arrayToString(data);
				//在这里调用ajax方法提交
				if (flg) {
					sendPost("/upm_manager/v1.0/business_subsystems", postSuccess,
							DialogAlert, jsonData, null);
				}
			}
		};
		$('#checkout-form').validate(option);
	};
	loadScript("js/plugin/jquery-form/jquery-form.min.js", pagefunction);
	$('#submitbtn').click(function() {
		DialogAlertClear();
		$('#checkout-form').submit();
	});

	function postSuccess(data) {
		//提交成功的方法
		$("#addModal").modal('toggle');
		sendGet("/upm_manager/v1.0/business_subsystems", reloadGrid, ListAlert,
				null);
	}

	function fillSelect_businessSystem(data) {
		businessSystem = $businessSystem[0].selectize;
		businessSystem.clearOptions();
		$.each(data['data'], function(k, v) {
			businessSystem.addOption(v);
		});
	}
</script>